const http = require("http")
const fs = require("fs")

const server = http.createServer((req, res) => {
  console.log(req.url, req.method);

  if (req.url == "/upload") {
    if (req.method == "POST") {
      const fileWrite = fs.createWriteStream("./foo.png", { flags: "a+" })
      res.on("data", (data) => {
        console.log(data);
        fileWrite.write(data)
      })
      res.on("end", () => {
        console.log("end");
      })
    }
  }
  res.end("end")
})

server.listen(8001, () => {
  console.log("服务器开启成功");
})